﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Lvzhi.Core;
using Lvzhi.Entities;
using Webdiyer.WebControls.Mvc;
using Lvzhi.AdminCenter.Extension.MvcHelper;

namespace Lvzhi.AdminCenter.Controllers
{
    public class LogController : BaseController
    {
        private UserGrantCore ugcore = new UserGrantCore();
        /// <summary>
        /// 出去的日志
        /// </summary>
        /// <returns></returns>
        public ActionResult Assign(int id = 1, int size = 10, string key = "",int f = 1)
        {
            var user = GetUser();

            ViewBag.F = f;
            ViewBag.RoleId = GetUser().U_Role;
            Expression<Func<Core_UserGrant, Boolean>> expr = t => t.UG_State == 0;

            if (GetUser().U_Role != 0)
            {
                expr = expr.And(t => t.UG_FromUId == user.U_Id);
            }

            if (!string.IsNullOrWhiteSpace(key))
            {
                expr = expr.And(t => t.UG_ToUName.Contains(key.Trim()));
            }
            if (f == 1)
            {
                expr = expr.And(t => t.UG_FromUId == user.U_Id);
            }else if (f == 2)
            {
                expr = expr.And(t => t.UG_ToUId == user.U_Id);
            }

            var list = ugcore.LoadEntities(expr).OrderByDescending(o => o.UG_Id).ToPagedList(id, size);
            return View(list);
        }
    }
}